package com.jetpackframework.basemd;

import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.FragmentTransaction;

import com.frameworkx.layout.frag_nav;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.jetpackframework.R;
import com.jetpackframework.R2;
import com.jetpackframework.base.BaseFragment;

import java.util.Map;

public abstract class BaseNavFragment extends BaseFragment<frag_nav> implements BottomNavigationView.OnNavigationItemSelectedListener {
    @Override
    protected View initView() {
        mBinding = getViewBind(R2.layout.frag_nav);
        View view = setContentView(mBinding.getLayoutId());
        mBinding.bindView(view);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mBinding.bnv.inflateMenu(getBottomMenu());
        mBinding.bnv.setOnNavigationItemSelectedListener(this);
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        BaseFragment fragment = getFragmentByMenu(item);
        FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
        transaction.replace(R.id.frame_content,fragment);
        transaction.commitAllowingStateLoss();
        return true;
    }
    protected abstract int getBottomMenu();
    protected abstract BaseFragment getFragmentByMenu(MenuItem item);
}
